package stu.day39_day.day40;

import java.util.Scanner;

public class hw3 {

    public static String  dp(String st1,String str2){
        int m=st1.length();
        int n=str2.length();
        int[][] dp=new int[m+1][n+1];

        int max =0;
        int x=0;
        int y=0;
        for(int i=1;i<=m;i++){
            for(int j=1;j<=n;j++){
                if(st1.charAt(i-1)==str2.charAt(j-1)){
                    dp[i][j] = dp[i-1][j-1]+1;
                    if(max<dp[i][j]){
                        max=dp[i][j];
                        x=i;
                        y=i-max;
                    }
                }
            }
        }

        return st1.substring(y,x);




    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str1 = sc.nextLine();
        String str2 = sc.nextLine();

        System.out.println(dp(str1,str2));

    }
}
